﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PcArduinoControl
{
	public class DigitalOutputPin :
		IDigitalPin
	{
		internal event DigitalOutputChangeHandler DigitalValueChanged;

		public byte Number { get; protected set; }
		public PinType Type { get { return PinType.Output; } }

		public DigitalValue DigitalValue
		{
			get
			{
				return mDigitalValue;
			}
			set
			{
				mDigitalValue = value;
				DigitalValueSet();
			}
		}

		protected virtual void DigitalValueSet()
		{
			OnDigitalValueChanged();
		}

		DigitalValue mDigitalValue;

		public DigitalOutputPin(byte pin)
		{
			Number = pin;
			mDigitalValue = DigitalValue.Low;
		}

		void OnDigitalValueChanged()
		{
			var valueChanged = DigitalValueChanged;
			if (valueChanged != null)
				valueChanged.Invoke(Number, mDigitalValue);
		}
	}
}
